package com.xsoft.logic.service.implement;


import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import com.xsoft.framework.service.BaseService;
import com.xsoft.logic.dao.CommonDao;
import com.xsoft.logic.model.GameBatchData;
import com.xsoft.logic.model.GameRefBatch;
import com.xsoft.logic.service.interfaces.BatchGameService;
import com.xsoft.web.util.FileProcessUtil;
import com.xsoft.web.util.FileUtil;
import com.xsoft.web.util.excel.ExcelImportUtil;

public class BatchGameServiceImpl extends BaseService implements BatchGameService
{
	
	private CommonDao commonDao;

	public CommonDao getCommonDao()
	{
		return commonDao;
	}

	public void setCommonDao(CommonDao commonDao)
	{
		this.commonDao = commonDao;
	}

	@Override
	public void save(File gameFile, String fileName,String gameName,String fuliType) throws IOException 
	{
		
			
			String batchCode = UUID.randomUUID().toString().replaceAll("-", "");
			List<GameBatchData> list = ExcelImportUtil.readPay(gameFile,gameName,fuliType,batchCode);
			
			if(list.size()>0){
			
				for(int i=0;i<list.size();i++){
					this.commonDao.save(list.get(i));
				}
				
				GameRefBatch vo = new GameRefBatch();
				vo.setBatchCode(batchCode);
				vo.setGameName(gameName);
				vo.setFuliType(fuliType);
				vo.setNcount(list.size());
				vo.setUseCount(0);
				vo.setState("1");
				vo.setCreatetime(new Date());
				this.commonDao.save(vo);
				
			}
		}
		
		



}
